package com.woniu.woniuproject.web;

import com.woniu.woniuproject.entity.LooseLabel;
import com.woniu.woniuproject.entity.Product;
import com.woniu.woniuproject.entity.User;
import com.woniu.woniuproject.mapper.*;
import com.woniu.woniuproject.utils.ResponseResult;
import com.woniu.woniuproject.vo.ProductAccountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:<br>
 * 〈〉
 *
 * @author EDZ
 * @create 2020/11/21
 * @since 1.0.0
 */
@RestController
@RequestMapping("indexweb")
public class IndexController {

    @Autowired
    UserMapper userMapper;
    @Autowired
    moneyCountMapper moneyCountMapper;
    @Autowired
    Product_accountMapper product_accountMapper;
    @Autowired
    ProductMapper productMapper;
    @Autowired
    LooseLabelMapper looseLabelMapper;

    @RequestMapping("/queryall")
    public ResponseResult<Map<String,Object>> queryall(){
        HashMap<String, Object> map = new HashMap<>();
        List<User> users = userMapper.selectAll();
        map.put("users",users.size());
        Double money = moneyCountMapper.selectmoney();
        map.put("money",money);
        Double allmoney=product_accountMapper.queryallmoney();
        map.put("allmoney",allmoney);
        List<Product> list = productMapper.selectall();
        map.put("product",list);
        List<LooseLabel> list2=looseLabelMapper.selectstatus4();
        map.put("LooseLabel",list2);
        System.out.println(list2);
        Date date = new Date();
        Date date1 = new Date();
        if(date.getDate()>7){
            date1.setDate(date.getDate()-7);
            //周排行
            List<ProductAccountVO> queryseven = product_accountMapper.queryseven(date, date1);
            map.put("queryseven",queryseven);
            //月排行
            date.setMonth(date.getMonth()-1);
            date1.setMonth(date1.getMonth()-1);
            date.setDate(30);
            date1.setDate(1);
            List<ProductAccountVO> queryseven1 = product_accountMapper.queryseven(date1, date);
            map.put("queryseven1",queryseven1);
            //总排行
            List<ProductAccountVO> queryseven2 = product_accountMapper.querysevenmore();
            map.put("queryseven2",queryseven2);
        }else{
            //周排行
            date1.setMonth(date.getMonth()-1);
            date1.setDate(30-date.getDate());
            List<ProductAccountVO> queryseven = product_accountMapper.queryseven(date, date1);
            map.put("queryseven",queryseven);
            //月排行
            date.setMonth(date.getMonth()-1);
            date.setDate(1);
            date1.setDate(30);
            List<ProductAccountVO> queryseven1 = product_accountMapper.queryseven(date, date1);
            map.put("queryseven1",queryseven1);
            //总排行
            List<ProductAccountVO> queryseven2 = product_accountMapper.querysevenmore();
            map.put("queryseven2",queryseven2);
        }



        return new ResponseResult<>(map);
    }

    @RequestMapping("username")
    public ResponseResult<String> username(HttpServletRequest req){
        User loginUser =(User) req.getSession().getAttribute("loginUser");

        return new ResponseResult<>(loginUser.getUsername());
    }

}